package LCR;

public class pivotIndex {
    public int pivotIndex(int[] nums) {
        int total = runSum(nums,0,nums.length -1);
        int sum = 0;
        for(int i =0;i < nums.length;i++) {
            if(2*sum + nums[i] == total) {
                return i;
            }
            sum += nums[i];
        }
        return -1;


    }

    int runSum(int[] nums,int left,int right ){
        int sum = 0;
        while(left <= right) {
            sum += nums[left];
            left++;
        }
        return sum;
    }
}
